﻿using System;

namespace Trentacular.SharePoint.StsAdmin
{
    public class BaseConsoleHelper
    {
        public int ErrorCount { get; private set; }

        public BaseConsoleHelper()
        {
            ErrorCount = 0;
        }

        protected void HandleError(Exception e, bool pad)
        {
            if (pad)
                Console.WriteLine();

            Console.WriteLine(e.Message);

            if (pad)
                Console.WriteLine();

            ErrorCount++;
        }

        protected void DoConsoleAction(string description, Action action)
        {
            Console.Write(string.Format("{0} ... ", description));
            try
            {
                action();
                Console.WriteLine("Success");
            }
            catch (Exception e)
            {
                HandleError(e, false);
            }
        }
    }
}
